<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>米线管理</title>
    <link rel="stylesheet" href="/public/admin/css/layui.css"  media="all">
    <script src="/public/index/css/jquery.min.js"></script>
    <script src="/public/admin/adminlink.js"></script>
    <style>
        .layui-table-cell{
            height: auto;
        }
    </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">海贼王米线</div>

        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a href="/adminout">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item">
                    <a class="" href="javascript:;">数据管理</a>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">米线管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">订单管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;">未接单</a></dd>
                        <dd><a href="javascript:;">已接单</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">配送员管理</a>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <div>
                <button class="layui-btn" id="addrice">添加米线</button>
            </div>

            <table class="layui-hide" id="test"></table>

        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        海贼王米线，欢迎您品尝。
    </div>
</div>
<script src="/public/admin/layui.all.js" charset="utf-8"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });
</script>
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?d214947968792b839fd669a4decaaffc";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'/admin_rice'
            ,cols: [[
                {field:'_id', width:200, title: '编号'}
                ,{field:'f_img', width:120, title: '缩略图', templet:'#f_img'}
                ,{field:'f_name', width:200, title: '名称'}
                ,{field:'f_marks', title: '描述'}
                ,{field:'f_price', title: '价格',width:160, sort: true}
                ,{field:'mydo', title: '操作', templet:'#mydo',width:150}
            ]]
            ,page: true
        });
    });
</script>
<script type="text/html" id="f_img">
    <img src="{{d.f_img}}" width="120" class="foodimg"/>
</script>
<script type="text/html" id="mydo">
    <button class="layui-btn layui-btn-sm" onclick="edit('{{d._id}}')">编辑</button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="del('{{d._id}}')">删除</button>
</script>
<script>
    $("#addrice").click(function () {
        layer.open({
            type: 2,
            title: '添加米线',
            shadeClose: true,
            shade: 0.8,
            area: ['600px', '550px'],
            content: '/admin_addricem' //iframe的url
        });
    });
    function del(id) {
        layer.confirm('您确定要删除此数据么？', {
            btn: ['确定','取消']
        }, function(){
            $.post("/admin_delrice", {id:id}, function (result) {
                if (result == 200) {
                    layer.msg("删除成功");
                    location.reload();
                } else {
                    layer.msg("删除失败");
                }
            });
        });

    }

    function edit(id) {
        layer.open({
            type: 2,
            title: '编辑米线',
            shadeClose: true,
            shade: 0.8,
            area: ['600px', '550px'],
            content: '/admin_editricem?id='+id //iframe的url
        });
        
    }
</script>

</body>
</html>